home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: Schildt <- Advanced Books
- Date: 8 Mar 96 20:47:04 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.826318024@rscernix>
- References: <8BA8405.02C70020DE.uuout@sourcebbs.com> <danpop.826121528@rscernix> <1996Mar7.162150.115560@kuhub.cc.ukans.edu>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <1996Mar7.162150.115560@kuhub.cc.ukans.edu> anh@kuhub.cc.ukans.edu writes:
-
- >Er, so what do you use instead of %d ?
-
- %d, of course :-)
-
- The clue is not to use a size_t value as a printf argument, because you
- simply cannot tell in advance what conversion specifier to use: %u or
- %lu. Cast the size_t to any type you want and use the right conversion
- specifier for that type: even %d will do.
-
- Note that %d can be used with an uncast size_t only on very exotic
- implementations, where sizeof(size_t) < sizeof(int). In such a case,
- the compiler will promote the size_t value to int. If size_t is
- defined as unsigned int, using %d invokes undefined behaviour.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-